package bo.zhao.action.simple_factory.factory;

import bo.zhao.action.simple_factory.product.ISender;
import bo.zhao.action.simple_factory.product.MailSender;
import bo.zhao.action.simple_factory.product.SMSSender;

public class EnumFactory {

	public static enum SenderType {
		MAIL(MailSender.class),
		SMS(SMSSender.class);
		
		private Class<? extends ISender> type;
		
		public Class<? extends ISender> getType() {
			return type;
		}

		private SenderType(Class<? extends ISender> type) {
			this.type=type;
		}
		
		
	}
	
	
	
	
	public ISender produce(SenderType senderType) {

	 
		ISender sender = null;
		
		try {
			sender = senderType.getType().newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		if(senderType==SenderType.MAIL) {
			sender.setDelay(9);
		}
		else if(senderType==SenderType.SMS) {
			sender.setDelay(21);
		}
		
		//调用初始化方法
		sender.init();
		sender.prepare();
		
		return sender;
	}
	
	 

}
